跳到主要内容

执行 git push 的时候出现报错

· 阅读需 1 分钟

报错信息:

# git push 

Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 511 bytes | 511.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
remote: fatal: not a git repository: '.'
remote: fatal: not in a git directory
remote: fatal: not a git repository: '.'
To xxxx.git
d124998..c69745a master -> master

原因:远程仓库的 git hooks 执行失败。 一般是 post-receive。在 post-receive 脚本中,有 cd 到其他目录执行 git 命令。

解决方法:git 在运行 hook 时,会自动设置一个 GIT_DIR-='.' 的环境变量。需要执行 unset GIT_DIR 来清除这个变量。